<?php
// +----------------------------------------------------------------------
// | Desc: [ Better-充值审核 ]
// +----------------------------------------------------------------------
// | Author: huangzhen_20210406
// +----------------------------------------------------------------------

namespace app\common\model;
use think\facade\Db;
use app\api\controller\Index;

class CardsTransCreditCd extends Common
{
    //---------------------------------------------后端---------------------------------------------------------------
    /**
     * 返回layui的table所需要的格式
     * @param $post
     * @param $user_id
     * @return mixed
     * @throws \think\db\exception\DbException
     */
    public function tableDataAdmin($post)
    {
        $list_rows  = $post['limit'] ?? config('paginate.list_rows');
        $page       = $post['page'] ?? config('paginate.page');

        $where =[];
        if(isset($post['user_name']) && !empty($post['user_name'])){
            $where[] = ['username', '=', trim($post['user_name'])];
        }
        if(isset($post['card_num']) && !empty($post['card_num'])){
            $where[] = ['ct.card_num', '=', trim($post['card_num'])];
        }
        if(isset($post['shopping']) && !empty($post['shopping'])){
            $where[] = ['ct.shopping', 'like', '%' . trim($post['shopping']) . '%'];
        }
        if(isset($post['credit_status']) && strlen($post['credit_status'])>0){
            $where[] = ['ct.credit_status', '=', trim($post['credit_status'])];
        }
        if(isset($post['datetime']) && !empty($post['datetime'])){
            $time_list = explode(' _ ' , $post['datetime']);
            $start_time = $time_list[0] . " 00:00:00";
            $end_time   = $time_list[1] . " 23:59:59";
            $where[] = ['ct.ctime', 'between', "{$start_time},{$end_time}"];
        }

        $list = Db::name('cards_trans_credit_cd')->alias('ct')
            ->leftJoin('user u' , 'u.id=ct.user_id')
            ->field('u.username,ct.*')
            ->order('ct.ctime desc')
            ->where($where)
            ->paginate(['list_rows' => $list_rows, 'page' => $page])
            ->toArray();
        return $result = [
            'code'  => 0,
            'msg'   => lang('get info success'),
            'data'  => $list['data'],
            'count' => $list['total'],
        ];
    }
}